package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.PageBean;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;


    @Override
    public Map<String, Object> findPage(PageBean pageBean) {
        Page<Object> page = PageHelper.startPage(pageBean.getCurrentPage(), pageBean.getPageSize());
        List<CheckItem> list = checkItemMapper.selectList(pageBean.getQueryString());
        PageInfo<CheckItem> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        List<CheckItem> list1 = pageInfo.getList();
        Map map = new HashMap<>();
        map.put("rows", list1);
        map.put("total", total);
        return map;
    }

    @Override
    public int add(CheckItem checkItem) {
            if (checkItem != null) {
                int i = checkItemMapper.insert(checkItem);
                return i;
            }
        return 0;
    }

    @Override
    public void deleteByid(Long id) {
        checkItemMapper.deleteById(id);
    }

    @Override
    public CheckItem findById(Long id) {
          CheckItem checkItem =  checkItemMapper.selectById(id);
        return checkItem;
    }

    @Override
    public void update(CheckItem checkItem) {
        checkItemMapper.update(checkItem);
    }

}
